﻿using Sirenix.OdinInspector;
using UnityEngine;
namespace PlantSystem
{
    public enum PlantLifeStatus
    {
        SEED,
        YOUNG,
        ADULT,
        OLD
    }

    public enum PlantWateringStatus
    {
        Dry,
        Normal,
        Drown,
    }
    public class PlantLifeCycle : MonoBehaviour
    {
        [BoxGroup("各时期Transform")]
        public Transform SeedTrans;
        [BoxGroup("各时期Transform")]
        public Transform YoungTrans;
        [BoxGroup("各时期Transform")]
        public Transform AdultTrans;
        [BoxGroup("各时期Transform")]
        public Transform OldTrans;

        [BoxGroup("各时期振动")]
        [LabelText("振动分时期")]
        public bool UseStatusShake = false;

        [BoxGroup("各时期振动")]
        [LabelText("振动幅度(Young)")]
        public float ShakeMagYoung = 1f;

        [BoxGroup("各时期振动")]
        [LabelText("振动幅度(Adult)")]
        public float ShakeMagAdult = 1f;

        [BoxGroup("各时期振动")]
        [LabelText("振动幅度(Old)")]
        public float ShakeMagOld = 1f;

        [OnValueChanged("RefreshStatusShow")]
        public PlantLifeStatus status;


        private Transform[] m_Transforms = new Transform[4];

        public float ShakeMag
        {
            get
            {
                if (status == PlantLifeStatus.YOUNG)
                    return ShakeMagYoung;
                if (status == PlantLifeStatus.ADULT)
                    return ShakeMagAdult;
                if (status == PlantLifeStatus.OLD)
                    return ShakeMagOld;
                return 0;
            }
        }

        void Awake()
        {
            m_Transforms[(int)PlantLifeStatus.SEED] = SeedTrans;
            m_Transforms[(int)PlantLifeStatus.YOUNG] = YoungTrans;
            m_Transforms[(int)PlantLifeStatus.ADULT] = AdultTrans;
            m_Transforms[(int)PlantLifeStatus.OLD] = OldTrans;
        }


        public Transform GetStatusTransform(PlantLifeStatus status)
        {
            return m_Transforms[(int)status];
        }

        public void SetStatusTransformActive(PlantLifeStatus status, bool active)
        {
            var trans = GetStatusTransform(status);
            if (trans != null)
            {
                trans.gameObject.SetActive(active);
            }
        }

        //public void UpdateWater()
        //{
        //    var grid = WorldUtil.GetGlobalGridPos(m_Unit.unitData.secPos, m_Unit.unitData.originPos);
        //    var poolGrid = GameData.Instance.worldSectionData.GetPoolGrid(grid);
        //    if (poolGrid != null)
        //    {

        //    }
        //}


#if UNITY_EDITOR
        [OnInspectorInit]
        public void RefreshStatusShow()
        {
            if (SeedTrans != null)
                SeedTrans.gameObject.SetActive(this.status == PlantLifeStatus.SEED);
            if (YoungTrans != null)
                YoungTrans.gameObject.SetActive(this.status == PlantLifeStatus.YOUNG);
            if (AdultTrans != null)
                AdultTrans.gameObject.SetActive(this.status == PlantLifeStatus.ADULT);
            if (OldTrans != null)
                OldTrans.gameObject.SetActive(this.status == PlantLifeStatus.OLD);
        }

#endif

    }
}